﻿using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace AIStudio.Core.Models
{
    public class AMenuItem : BindableBase
    {
        private string _glyph;
        public string Glyph
        {
            get { return _glyph; }
            set
            {
                SetProperty(ref _glyph, value);
            }
        }

        private string _label;
        public string Label
        {
            get { return _label; }
            set
            {
                SetProperty(ref _label, value);
            }
        }

        public string Code { get; set; }//区分点击的菜单

        public string WpfCode
        {
            get
            {
                if (Code == null)
                    return null;

                var subcode = Code.Replace("/Index", "IndexView").Replace("/TreeList", "TreeView").Replace("/List", "View").Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
                if (subcode.Length == 1)
                    return Code;

                subcode[subcode.Length - 1] = $"Views.{subcode[subcode.Length - 1]}";

                if (!subcode[subcode.Length - 1].EndsWith("View"))
                {
                    subcode[subcode.Length - 1] = subcode[subcode.Length - 1] + "View";
                }

                return $"AIStudio.Wpf.{string.Join(".", subcode)}";
            }
        }


        public int Type { get; set; }//区分菜单还是目录

        public AMenuItem Parent { get; set; }
        public string Id { get; set; }
        public string ParentId { get; set; }

        private ICommand _command;
        public ICommand Command
        {
            get { return _command; }
            set
            {
                SetProperty(ref _command, value);
            }
        }

        private ObservableCollection<AMenuItem> _children = new ObservableCollection<AMenuItem>();

        public ObservableCollection<AMenuItem> Children
        {
            get { return _children; }
            set
            {
                SetProperty(ref _children, value);
            }
        }

        public void AddChildren(AMenuItem child)
        {
            this.Children.Add(child);
        }
    }
}
